package com.runfast.waimai.web.controller;

import com.runfast.common.utils.TokenUtil;
import com.runfast.common.web.entity.Result;
import com.runfast.paotui.service.RunfastAgentbusinessService;
import com.runfast.waimai.dao.model.BsTravelAdvert;
import com.runfast.waimai.dao.model.RunfastBusiness;
import com.runfast.waimai.dao.model.RunfastHomepage;
import com.runfast.waimai.service.BsTravelAdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 跑腿订单接口
 */
@RestController("userWmBusinessController")
@RequestMapping(value= "/api/user/wm/business", headers = "token")
public class BusinessController {


    @Autowired
    private BsTravelAdvertService advertService;


    @Autowired
    private RunfastAgentbusinessService agentbusinessService;
    /**
     *
     * 根据用户当前的位置获取默认的代理商id
     * @param longitude 用户当前的经度
     * @param latitude 用户当前的维度
     * @param token
     * @return
     */
    @PostMapping("/agent")
    public Result agent(@RequestParam double longitude, @RequestParam double latitude, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);

        Integer agentId = agentbusinessService.getDefaultAgentId(longitude, latitude);

        return Result.ok("", agentId);
    }

    /**
     * 根据代理商id获取首页轮播广告列表
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/adverts")
    public Result<List<BsTravelAdvert>> adverts(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);



        return Result.ok("");
    }


    /**
     * 根据代理商id获取首页商户分类
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/catalogs")
    public Result<List<RunfastHomepage>> catalogs(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }


    /**
     *
     * 获取附近商家
     * @param longitude 用户当前经度
     * @param latitude 用户当前维度
     * @param sorting 排序方式
     * @param filter 刷选方式
     * @param catalogId 商户分类id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/businessNearBy")
    public Result<List<RunfastBusiness>> businessNearBy(@RequestParam double longitude, @RequestParam double latitude, @RequestParam int sorting, @RequestParam int filter, @RequestParam int catalogId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }



}
